const network_utils = require('../../../../../http/NetworkUtils.js');
const constants = require('../../../../../common/Constants.js');
import PickerUtils from '../../../../../model/PickerUtils';
import location from '../../../../../common/code/pickerList/location';
import busTypes from '../../../../../common/code/pickerList/busTypes';
import PageRouter from '../../../../../utils/PageRouter';
import * as StateUtils from '../../../../../model/StateUtils';

let storeId1 = null;
let storeNickName = "";
let fromPage="";
Page({
    data: {
        storeInfo: _getStoreInfoArr(),
        qrCodeList: [{index: 0, code: '', active: true}],
    },
    onLoad: function (options) {
      this.setData({
        storeId:options.storeId
      })
        // 页面初始化 options为页面跳转所带来的参数
        let that = this;
        storeNickName = "";
        fromPage = JSON.parse(options.params).fromPage;
        let params = {
            storeId: options.storeId
        };
        storeId1 = options.storeId;
        network_utils.buildRequest(constants.Interfaces.FUNC_Merchant_STOREINFO, params, {
            doHttpSucess: function (data) {
                if (constants.RetCodes.SUCCESS === data.retCode) {

                    that.setData({
                        //  qrCodeList: _getCodeList(data["qrCodeList"]),
                        storeInfo: _getStoreInfoArr(data),
                        isOpenPos: data.isOpenPos,
                        storeAddress: data["storeRegion"],
                        // type:data["type"]
                    });
                    return true;
                }
                return false;
            },

        }).send();

    },

    addPos:function(){
      wx.redirectTo({
        url: '/pages/basisInfo/openPos/openPos?posFrom=detail&storeId=' + this.data.storeId+'&storeAddress='+this.data.storeAddress,
      })
    },
    openPos:function(){
      wx.navigateTo({
        url: '/pages/selfhelpDeployment/deploymentDetails/posDetails/posDetails?storeId=' + this.data.storeId
      })

    },
    openImPay: function () {
        let url = '../../../../basisInfo/openImPay/openImPay?pageState=desployRateDisable&storeId=' + storeId1;
        PageRouter.wxNavigateTo(this, url, fromPage === 'searchStores'|| fromPage === "clerkTransOverview");
    }

});

function _getStoreInfoArr(result) {
    let arr = [];
    arr.push({title: "商户简称", content: result && result["storeNickName"] ? result["storeNickName"] : ""});
    storeNickName = result && result["storeNickName"] ? result["storeNickName"] : "";
    arr.push({title: "商户全称", content: result && result["storeName"] ? result["storeName"] : ""});
    arr.push({
        title: "商户地址",
        content: result && result["storeRegion"] ? PickerUtils.getLinkedHZByCode(location, result["storeRegion"]).join("/") : ""
    });
    arr.push({title: "详细地址", content: result && result["storeAddress"] ? result["storeAddress"] : ""});
    arr.push({
        title: "商户类别",
        content: result && result["storeType"] ? PickerUtils.getLinkedHZByCode(busTypes, result["storeType"]).join("/") : ""
    });
    arr.push({title: "联系人号码", content: result && result["payeeMobile"] ? result["payeeMobile"] : ""});
    arr.push({title: "收款人", content: result && result["payeeName"] ? result["payeeName"] : ""});
    arr.push({title: "身份证号码", content: result && result["identity"] ? result["identity"] : ""});
    arr.push({title: "业务员", content: result && result["userName"] ? result["userName"] : ""});
    arr.push({title: "代理商编号", content: result && result["agentId"] ? result["agentId"] : ""});
    arr.push({title: "代理商简称", content: result && result["agentName"] ? result["agentName"] : ""});
    arr.push({ title: "商户号", content: result && result["storeId"] ? result["storeId"] : "" });
    arr.push({ title: "店铺状态", content: result && result["registerProcsState"] ? new StateUtils.registProcssState(result["registerProcsState"]).title : "" });
    arr.push({ title: "标签一", content: result && result["labelOne"] ? result["labelOne"] : "" });
    arr.push({ title: "标签二", content: result && result["labelTwo"] ? result["labelTwo"] : "" });
    return arr;
};